import json

import click
from flask import Blueprint
from rich import print as rprint
from rich.console import Console
from rich.json import JSON
from rich.table import Table

from src.console import theme

BlueprintConsoleHello = Blueprint('hello', __name__)


@BlueprintConsoleHello.cli.command('boy')
@click.argument('name')
def boy(name):
    """
    用法： flask hello boy jim
    """
    console = Console(theme=theme)
    # 打印行
    console.print("这是普通信息", style="info")
    console.print("⚠️ 警告：配置文件未找到", style="warning")
    console.print("❌ 错误：数据库连接失败", style="error")
    console.print("✅ 成功：服务已启动", style="success")
    console.print("-" * 50, style="line")
    # 打印表格
    table = Table(title="用户列表")
    table.add_column("ID", style="cyan")
    table.add_column("姓名", style="magenta")
    table.add_column("状态", style="green")
    table.add_row("1", "Alice", "在线")
    table.add_row("2", "Bob", "离线")
    console.print(table)
    # 打印json
    rprint(name)
    rprint(JSON(json.dumps({"name": name, "age": 30})))
    rprint(JSON('{"name": "Alice", "age": 30}'))
